package ibmetp.mis.controller.resource;



import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.ResourceService;
import ibmetp.mis.serviceImpl.ResourceServiceImpl;
import ibmetp.mis.vo.Resource;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;

public class ResourceAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ResourceAddServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		System.out.println("Call ResourceAddServlet...");
		//获取参数
		Resource resource = new Resource();
		resource.setParentId(Long.valueOf(request.getParameter("parentId")));
		resource.setResourceName(request.getParameter("resourceName"));
		resource.setUrl(request.getParameter("url"));
		resource.setDescript(request.getParameter("descript"));
		    
		ResourceService  rs=new ResourceServiceImpl();

	    String result=rs.addresource(resource);
	  //如果有返回消息，则将消息发回页面
		if(result!=null){		
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message(result)));
		}
	    
	}
}

